/**
 * Created by shenhai on 15/9/11.
 */


angular.module('mis.logManager.controllers', [])
    .controller('logCtrl', ['$scope','$http', '$location', function ($scope, $http, $location) {
        //gObj.getFile("/public/js/common/loadResource.js");
        //初始化左右选择框
        var larSelect = new gObj.larSelect();
        $scope.currentPage = 1;
        $scope.pageSize = 15;

        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/log/logList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.logList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");

            },
            error: function(err){
                $scope.logList = null;
            },
            params: {}
        });


        $scope.search = function() {

            $scope.pagination.currentPage = 1;
            $scope.currentPage = 1;

            var body = {};
            if ($scope.desc) body.username = $scope.desc;

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/log/logList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                $scope.logList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;

            }).error(function () {
                $scope.logList = null;
            });
        };


        //全选列表
        $scope.allSelected = function(){
            $scope.pagination.allSelected();
        };

        //删除
        $scope.delete = function(){
            var params = {
                url: 'http://' + backOfficeHost + '/rest/v1.0/mis/log/logDelete',
                checkObj: $(".item-check"),//checkbox对象
                key:"logID",
                success: function(data){
                    var number = $(".am-active").text();//当前页码
                    $scope.pagination.selectPage(number);
                },
                error: function(err){}
            };
            $scope.pagination.listDelete(params);
        };

    }]);